import { GetterTree, ActionTree, MutationTree, Commit } from 'vuex'

import { RootState } from '@/store/modules/types'

import * as http from '@/http/common'

export const state: RootState = {
  icons: []
}

export const getters: GetterTree<RootState, any> = {

}

export const mutations: MutationTree<RootState> = {
  /**
   * 设定图标
   *
   * @param state
   * @param data
   */
  setIcons(state: RootState, data) {
    state.icons = data
  }
}

export const actions: ActionTree<RootState, any> = {
  /**
   * 获取图标
   *
   * @param commit
   * @param payload
   */
  getIcons({commit}: { commit: Commit }, payload?: any) {
    return http.getIcon(payload.param).then((res: any) => {
      if (res.status === 200) {
        commit('setIcons', res.data)
      }
      
      return res
    })
  },
  
  /**
   * 验证码
   *
   * @param commit
   * @param payload
   */
  getCaptcha({commit}: { commit: Commit }, payload?: any) {
    return http.getCaptcha(payload.param)
  }
}
